package com.uuah.server.transport.provider.mina;

import com.uuah.server.transport.AbstractMessageAdapter;

/**
 *
 * @author jonny
 *
 */
public class MinaMessageAdapter extends AbstractMessageAdapter {

    private static final long serialVersionUID = 3845314363407167530L;

    private Object payload;

    public MinaMessageAdapter(Object message)
    {
        this.payload = message;
    }

    protected MinaMessageAdapter(MinaMessageAdapter template)
    {
        payload = template.payload;
    }

    public String getPayloadAsString(String encoding) throws Exception {
        if(payload instanceof String) {
        	return new String((String)payload);
        }
        else {
        	return payload.toString();
        }
    }

    public byte[] getPayloadAsBytes() throws Exception
    {
        return payload.toString().getBytes();
    }

    public Object getPayload()
    {
        return payload;
    }

    public String toString() {
    	return this.payload.toString();
    }

}
